package com.pub.util;

import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;

import java.io.InputStream;
import java.io.StringReader;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;


public class XmlHelper {
	 public static  boolean readXml(String xml, DefaultHandler handler){
	    SAXParserFactory saxparserfactory = SAXParserFactory.newInstance();
	    SAXParser saxparser;
		try {
			saxparser = saxparserfactory.newSAXParser();
			saxparser.parse(
					new InputSource(new StringReader(xml))
					  ,handler);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	  }
	 public static  boolean readXml(InputStream input, DefaultHandler handler){
	      SAXParserFactory saxparserfactory = SAXParserFactory.newInstance();
	      SAXParser saxparser;
		try {
			saxparser = saxparserfactory.newSAXParser();
			saxparser.parse(
					new InputSource(input)
					  ,handler);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	  }
}
